package com.fixme4trade.view;

import java.util.List;

import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.ServletResponse;

import br.gov.frameworkdemoiselle.annotation.Name;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.util.Parameter;

import com.fixme4trade.business.SellBC;
import com.fixme4trade.domain.Sell;
import com.fixme4trade.template.PagedListPageBean;

@ViewController
//@NextView("/auth/payment_edit.xhtml")
@PreviousView("/public/product_show.xhtml")
public class ShoppingCartListMB extends PagedListPageBean<Sell, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private SellBC bc;
	
	@Inject
	@Name("sellId")
	Parameter<Long> sellId;

	@Override
	protected List<Sell> handleResultList() {
		try {
			return this.bc.getShoppingCart();
		} catch (Exception e) {	
			e.printStackTrace();
			return null;
		}		
	}

	@Override
	protected void handleDelete(Long id) {
		this.bc.delete(id);		
	}
	
	public String payItem() {
		System.out.println("SellID (1) = "+sellId.getValue());
		//FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("sellId", );
		return "/auth/payment_edit.jsf?sellId="+sellId.getValue();
	}
}
